package com.itheima.springbootmybatisquickstart.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.springbootmybatisquickstart.mapper.DeptMapper;
import com.itheima.springbootmybatisquickstart.pojo.Dept;
import com.itheima.springbootmybatisquickstart.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper,Dept> implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> findAll() {

//        return deptMapper.selectList(null);
        return list();      //查询所有
    }

    @Override
    public void deleteById(Integer id) {
        deptMapper.deleteById(id);
    }

    @Override
    public void save2(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }

    @Override
    public Dept getById(Integer id) {
        return deptMapper.selectById(id);
    }

//    @Override
//    public void update(Dept dept) {
//        dept.setUpdateTime(LocalDateTime.now());
//        deptMapper.updateById(dept);
//    }
    @Override
    public void update(Dept dept) {
        // 补全基础属性
        dept.setUpdateTime(LocalDateTime.now());
//        deptMapper.updateById(dept);
        deptMapper.update(dept);
    }

}